<!DOCTYPE html>
<html class="has-navbar-fixed-top">
<head><meta name="generator" content="Hexo 3.8.0">
    <meta charset="utf-8">
<title>Install Python and pip - HANZO</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/outdated-browser/1.1.5/outdatedbrowser.min.css">


<meta name="description" content="鬼王, HANZO, THRAEX">



<meta name="keywords" content="鬼王, O70, HANZO, THRAEX">



    <meta name="description" content="On Windows10Install Python3 Download Python 3.7.0, choose Windows x86-64 embeddable zip file  解压至C:\Workspace\Kits\python3.7  配置环境变量%KITS_HOME%\python3.7  Open terminal: python -V or python   Question">
<meta name="keywords" content="鬼王, O70, HANZO, THRAEX">
<meta property="og:type" content="article">
<meta property="og:title" content="Install Python and pip">
<meta property="og:url" content="http://yoursite.com/documents/others/install-python-and-pip.html">
<meta property="og:site_name" content="HANZO">
<meta property="og:description" content="On Windows10Install Python3 Download Python 3.7.0, choose Windows x86-64 embeddable zip file  解压至C:\Workspace\Kits\python3.7  配置环境变量%KITS_HOME%\python3.7  Open terminal: python -V or python   Question">
<meta property="og:locale" content="en">
<meta property="og:updated_time" content="2019-07-26T04:02:09.403Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Install Python and pip">
<meta name="twitter:description" content="On Windows10Install Python3 Download Python 3.7.0, choose Windows x86-64 embeddable zip file  解压至C:\Workspace\Kits\python3.7  配置环境变量%KITS_HOME%\python3.7  Open terminal: python -V or python   Question">





<link rel="icon" href="/images/favicon.ico">


<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Ovo|Source+Code+Pro">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bulma/0.6.2/css/bulma.min.css">


<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/lightgallery/1.6.8/css/lightgallery.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/justifiedGallery/3.6.5/css/justifiedGallery.min.css">


<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/atom-one-dark.min.css">

<link rel="stylesheet" href="/css/style.css">

<script defer src="//use.fontawesome.com/releases/v5.0.8/js/all.js"></script>



</head>
<body>
    
<nav class="navbar is-transparent is-fixed-top navbar-main" role="navigation" aria-label="main navigation">
    <div class="container">
        <div class="navbar-brand">
            <a class="navbar-item navbar-logo" href="/">
                
                    
                    HANZO
                    
                
            </a>
            <div class="navbar-burger">
                <span></span>
                <span></span>
                <span></span>
            </div>
        </div>
        
        <div class="navbar-menu navbar-start">
            
            <a class="navbar-item " href="/categories/Technology">Technology</a>
            
            <a class="navbar-item " href="/categories/Life">Life</a>
            
            <a class="navbar-item " href="/archives">Archives</a>
            
            <a class="navbar-item " href="/about">About</a>
            
            <a class="navbar-item " href="/main">Main</a>
            
        </div>
        
        <div class="navbar-menu navbar-end">
            
            <a class="navbar-item search" title="Search" href="javascript:;">
                <i class="fas fa-search"></i>
            </a>
            
            
            
            <a class="navbar-item" title="GitHub" href="https://github.com/O70">
                
                <i class="fab fa-github"></i>
                
            </a>
               
            
        </div>
    </div>
</nav>

    <section class="section">
    <div class="container">
    <article class="article content gallery" itemscope="" itemprop="blogPost">
    <h1 class="article-title is-size-3 is-size-4-mobile" itemprop="name">
        
            Install Python and pip
        
    </h1>
    <div class="article-meta columns is-variable is-1 is-multiline is-mobile is-size-7-mobile">
        <span class="column is-narrow">
            <time datetime="2019-06-17T05:40:00.000Z" itemprop="datePublished">Jun 17 2019</time>
        </span>
        
        
        <span class="column is-narrow">
            
            
            12 minutes read (About 1757 words)
        </span>
        
    </div>
    <div class="article-entry is-size-6-mobile" itemprop="articleBody">
    
        <h2 id="On-Windows10"><a href="#On-Windows10" class="headerlink" title="On Windows10"></a>On Windows10</h2><h3 id="Install-Python3"><a href="#Install-Python3" class="headerlink" title="Install Python3"></a>Install Python3</h3><ol>
<li><p>Download <a href="https://www.python.org/downloads/release/python-370/" target="_blank" rel="noopener">Python 3.7.0</a>, choose <strong>Windows x86-64 embeddable zip file</strong></p>
</li>
<li><p>解压至<code>C:\Workspace\Kits\python3.7</code></p>
</li>
<li><p>配置环境变量<code>%KITS_HOME%\python3.7</code></p>
</li>
<li><p>Open terminal: <code>python -V</code> or <code>python</code></p>
</li>
</ol>
<p><strong>Questions:</strong></p>
<ul>
<li>输入<code>help</code>/<code>exit()</code>报以下错误<figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&gt;&gt;&gt; help</span><br><span class="line">Traceback (most recent call last):</span><br><span class="line">  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;</span><br><span class="line">NameError: name &apos;help&apos; is not defined</span><br><span class="line"></span><br><span class="line">&gt;&gt;&gt; exit()</span><br><span class="line">Traceback (most recent call last):</span><br><span class="line">  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;</span><br><span class="line">NameError: name &apos;exit&apos; is not defined</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p><strong>打开<code>python37._pth</code>文件，去掉<code># import site</code>的注释，然后保存。上述问题解决。</strong></p>
<p><strong><code>python37._pth</code></strong>:<br><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">python37.zip</span><br><span class="line">.</span><br><span class="line"></span><br><span class="line"># 与import site作用相同</span><br><span class="line"># Lib\site-packages</span><br><span class="line"></span><br><span class="line"># Uncomment to run site.main() automatically</span><br><span class="line">import site</span><br></pre></td></tr></table></figure></p>
<blockquote>
<p>开启<code>import site</code>很重要，否则接下来安装<code>pip</code>也会失败。</p>
</blockquote>
<h3 id="Install-pip"><a href="#Install-pip" class="headerlink" title="Install pip"></a>Install pip</h3><blockquote>
<p><a href="https://pip.pypa.io/en/stable/installing/" target="_blank" rel="noopener">Do I need to install pip?</a></p>
</blockquote>
<ol>
<li><p>Download and install</p>
<figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py</span><br><span class="line"></span><br><span class="line">python get-pip.py</span><br></pre></td></tr></table></figure>
</li>
<li><p>配置环境变量<code>%KITS_HOME%\python3.7\Scripts</code></p>
</li>
<li><p>New terminal</p>
<figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">pip</span><br><span class="line"></span><br><span class="line">Traceback (most recent call last):</span><br><span class="line">  File &quot;runpy.py&quot;, line 193, in _run_module_as_main</span><br><span class="line">  File &quot;runpy.py&quot;, line 85, in _run_code</span><br><span class="line">  File &quot;C:\Workspace\Kits\python3.7\Scripts\pip.exe\__main__.py&quot;, line 5, in &lt;module&gt;</span><br><span class="line">ModuleNotFoundError: No module named &apos;pip&apos;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p><strong>在<code>python37._pth</code>中去掉<code># import site</code>的注释或添加<code>Lib\site-packages</code></strong></p>
<h3 id="查找模块"><a href="#查找模块" class="headerlink" title="查找模块"></a><a href="https://docs.python.org/zh-cn/3/using/windows.html?highlight=_pth#finding-modules" target="_blank" rel="noopener">查找模块</a></h3><p><strong><code>python37._pth</code> to <code>python37._pth_bak</code></strong></p>
<p>Python通常将其库（以及您的site-packages文件夹）存储在安装目录中。因此，如果您已将Python安装到<code>C:\Python\</code>，则默认库将驻留在 <code>C:\Python\Lib\</code>中，第三方模块存储在<code>C:\Python\Lib\site-packages\</code>。</p>
<p>若要完全覆盖<code>sys.path</code>，请创建与DLL(<code>python37._pth</code>)或可执行文件(<code>python._pth</code>)同名的<code>._pth</code>文件，并为要添加的每个路径指定一行<code>sys.path</code>。基于DLL名称的文件覆盖基于可执行文件的文件，如果需要，可以为加载运行时的任何程序限制路径。</p>
<p>当文件存在时，将忽略所有注册表和环境变量，启用隔离模式，并且：除非文件中的一行指定<code>import site</code>，否则不会导入<code>site</code>。以<code>＃</code>开头的空白路径和行将被忽略。每个路径可以是绝对的或相对于文件的位置。不允许使用除<code>site</code>以外的导入语句，并且不能指定任意代码。</p>
<p>请注意，当指定<code>import site</code>时，<code>.pth</code>文件（没有前导下划线）将由<code>site</code>模块正常处理。</p>
<p>当找不到<code>._pth</code>文件时，<code>sys.path</code>是如何在Windows上填充的：</p>
<ul>
<li><p>在开始时，添加一个空条目，该条目对应于当前目录。</p>
</li>
<li><p>如果环境变量<code>PYTHONPATH</code>存在，如<code>环境变量</code>中所述，则接下来添加其条目。请注意，在Windows上，此变量中的路径必须用分号分隔，以区别于驱动器标识符中使用的冒号（<code>C:\</code>等）。</p>
</li>
<li><p>附加的<code>&quot;application paths&quot;</code>可以同时添加到注册表<code>HKEY_CURRENT_USER</code>和<code>HKEY_LOCAL_MACHINE</code>分支下的: <code>samp:\SOFTWARE\Python\PythonCore\{version}\PythonPath</code>中作为子键。以分号分隔的路径字符串作为默认值的子键将导致每个路径添加到<code>sys.path</code>。（请注意，所有已知的安装程序都只使用HKLM，因此HKCU通常为空。）</p>
</li>
<li><p>如果设置了环境变量<code>PYTHONHOME</code>，则将其假定为 “Python 主目录” 。否则，主Python可执行文件的路径用于定位 “landmark 文件” （<code>Lib\os.py</code>或<code>pythonXY.zip</code>）以推断 ”Python 主目录“ 。如果找到了Python主目录，则基于该文件夹将相关的子目录添加到<code>sys.path</code>（<code>Lib</code> , <code>plat-win</code>等）。否则，核心Python路径是从存储在注册表中的PythonPath构造的。</p>
</li>
<li><p>如果找不到Python Home，也没有指定<code>PYTHONPATH</code>环境变量，并且找不到注册表项，则使用具有相对条目的默认路径（例如<code>.\Lib;</code> <code>.\plat-win</code>等等）。</p>
</li>
</ul>
<p>如果在主可执行文件旁边或在可执行文件上一级的目录中找到 pyvenv.cfg 文件，则以下变体适用：</p>
<ul>
<li>如果<code>home</code> 是一个绝对路径，并且<code>PYTHONHOME</code>未设置，则在推断起始位置时使用此路径而不是主可执行文件的路径</li>
</ul>
<p>这一切的最终结果是：</p>
<ul>
<li><p>运行<code>python.exe</code>，或主Python目录中的任何其他.exe（安装版本，或直接来自PCbuild目录）时，推导出核心路径，并忽略注册表中的核心路径。始终读取注册表中的其他“应用程序路径”。</p>
</li>
<li><p>当Python托管在另一个.exe（不同的目录，通过COM嵌入等）时，将不会推断出“Python Home”，因此使用了来自注册表的核心路径。始终读取注册表中的其他“应用程序路径”。</p>
</li>
<li><p>如果Python找不到它的主目录并且没有注册表值（冻结的.exe，一些非常奇怪的安装设置），那么你会得到一条带有一些默认但相对的路径的路径。</p>
</li>
</ul>
<p>对于那些想要将Python捆绑到其应用程序或发行版中的人，以下建议将防止与其他安装冲突：</p>
<ul>
<li><p>在您的可执行文件中包含一个<code>._pth</code>文件，其中包含目录。这将忽略注册表和环境变量中列出的路径，并忽略<code>site</code>，除非列出<code>import site</code>。</p>
</li>
<li><p>如果你在自己的可执行文件中加载<code>python3.dll</code>或<code>python37.dll</code>，在<code>Py_Initialize()</code>之前，要显式调用<code>Py_SetPath()</code>或（至少）<code>Py_SetProgramName()</code></p>
</li>
<li><p>清除和/或 覆盖<code>PYTHONPATH</code>并在启动来自应用程序的<code>python.exe</code>之前设置<code>PYTHONHOME</code>。</p>
</li>
<li><p>如果您不能使用前面的建议（例如，您是一个允许人们直接运行：<code>file:python.exe</code>的分发版），请确保安装目录中存在<code>landmark</code>文件（:file:<code>Lib\os.py</code>）。（请注意，在zip文件中不会检测到该文件，但会检测到正确命名的zip文件。）</p>
</li>
</ul>
<p>这些将确保系统范围安装中的文件不会优先于与应用程序捆绑在一起的标准库的副本。否则，用户可能会在使用您的应用程序时遇到问题请注意，第一个建议是最好的，因为其他建议可能仍然容易受到注册表和用户站点包中的非标准路径的影响。</p>
<p>在 3.6 版更改:</p>
<ul>
<li><p>添加<code>._pth</code>文件支持并从<code>pyvenv.cfg</code>中删除<code>applocal</code>选项</p>
</li>
<li><p>当直接与可执行文件相邻时，添加<code>pythonXX.zip</code>作为潜在的<code>landmark</code>。</p>
</li>
</ul>
<p>3.6 版后已移除:<br>在<code>Modules</code>（不是<code>PythonPath</code>）下的注册表中指定的模块可以通过以下方式导入<code>importlib.machinery.WindowsRegistryFinder</code>。在Windows上，此查找程序在3.6.0及更早版本的可用，但可能需要在将来显式添加到<code>sys.meta_path</code></p>

    
    </div>
    
    
    <div class="columns is-mobile is-multiline article-nav">
        <span class="column is-12-mobile is-half-desktop  article-nav-prev">
            
            <a href="/documents/others/nginx-test.html">Nginx Test</a>
            
        </span>
        <span class="column is-12-mobile is-half-desktop  article-nav-next">
            
            <a href="/documents/others/multiple-remote-push.html">Multiple Remote Push</a>
            
        </span>
    </div>
    
</article>





    </div>
</section>
    <footer class="footer">
    <div class="container">
        <div class="columns content">
            <div class="column is-narrow has-text-centered">
                Copyright &copy; 2019 鬼王&nbsp;
                <!-- Powered by <a href="https://github.com/O70" target="_blank">O70</a> -->
            </div>
            <div class="column is-hidden-mobile"></div>

            
            <div class="column is-narrow">
                <div class="columns is-mobile is-multiline is-centered">
                
                    
                <a class="column is-narrow has-text-black" title="京ICP备19029828号" href="http://www.miitbeian.gov.cn">
                    
                    京ICP备19029828号
                    
                </a>
                
                    
                <a class="column is-narrow has-text-black" title="GitHub" href="https://github.com/O70">
                    
                    GitHub
                    
                </a>
                
                </div>
            </div>
            
            

        </div>
    </div>
</footer>

    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment-with-locales.min.js"></script>

<!-- test if the browser is outdated -->
<div id="outdated">
    <h6>Your browser is out-of-date!</h6>
    <p>Update your browser to view this website correctly. <a id="btnUpdateBrowser" href="http://outdatedbrowser.com/">Update my browser now </a></p>
    <p class="last"><a href="#" id="btnCloseUpdateBrowser" title="Close">&times;</a></p>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/outdated-browser/1.1.5/outdatedbrowser.min.js"></script>
<script>
    $(document).ready(function () {
        // plugin function, place inside DOM ready function
        outdatedBrowser({
            bgColor: '#f25648',
            color: '#ffffff',
            lowerThan: 'flex'
        })
    });
</script>

<script>
    window.FontAwesomeConfig = {
        searchPseudoElements: true
    }
    moment.locale("en-AU");
</script>



<script src="/js/script.js"></script>


    
    <div class="searchbox ins-search">
    <div class="searchbox-mask"></div>
    <div class="searchbox-container ins-search-container">
        <div class="searchbox-input-wrapper">
            <input type="text" class="searchbox-input ins-search-input" placeholder="Type something...">
            <span class="searchbox-close ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="searchbox-result-wrapper ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
    (function (window) {
        var INSIGHT_CONFIG = {
            TRANSLATION: {
                POSTS: 'Posts',
                PAGES: 'Pages',
                CATEGORIES: 'Categories',
                TAGS: 'Tags',
                UNTITLED: '(Untitled)',
            },
            CONTENT_URL: '/content.json',
        };
        window.INSIGHT_CONFIG = INSIGHT_CONFIG;
    })(window);
</script>
<script src="/js/insight.js"></script>
    
</body>
</html>
